package hiatao.puzzle.config;

import hiatao.puzzle.entity.User;
import hiatao.puzzle.utils.Tools;

import android.app.Application;
import android.content.Context;
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;


public class MyApplication extends Application {

	public static Context applicationContext;
	private static MyApplication instance;
	public boolean isLogin = false;
	public boolean hasChage = false;
	public User user;

	/**
	 * 当前用户nickname,为了苹果推送不是userid而是昵称
	 */
	public static String currentUserNick = "";

	
	@Override
	public void onCreate() {
		super.onCreate();
        applicationContext = this;
        instance = this;
        instance = this;
        Tools.setContext(this);
        initImageLoader(getApplicationContext());
	}

	public static MyApplication getInstance() {
		return instance;
	}

    public static void initImageLoader(Context context) {
        // Create default options which will be used for every
        // displayImage(...) call if no options will be passed to this method
        DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
                .cacheInMemory(true).cacheOnDisc(true).build();

        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                context)
                .threadPoolSize(3)
                // default
                .threadPriority(Thread.NORM_PRIORITY - 1)
                // default
                .tasksProcessingOrder(QueueProcessingType.LIFO)
                .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
                .memoryCacheSizePercentage(13) // default
                .defaultDisplayImageOptions(defaultOptions)
                // .writeDebugLogs() // Remove for release app 日志log
                .build();
        // Initialize ImageLoader with configuration.
        ImageLoader.getInstance().init(config);
    }
}
